package Dungeon;

import static org.junit.Assert.*;

import java.util.HashSet;
import java.util.Set;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import SquarePackage.NormalSquare;
import SquarePackage.Square;

public class DungeonTest {
	
	private Dungeon<NormalSquare> c ;
	private Dungeon<Square> v ;
	private NormalSquare st;
	private NormalSquare st2;
	private NormalSquare st3;
	private static Dimension d;
	private static Dimension d2;
	private static Dimension d3;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		d = new Dimension(2,3,0);
		d2 = new Dimension(8,3,0);
		d3 = new Dimension(3,3,0);
	}
	
	@Before
	public void setUp() throws Exception {
		st = new NormalSquare();
		st2 = new NormalSquare();
		st3 = new NormalSquare();
		c = new Shaft<NormalSquare>(new Dimension(0,0,10));
		v = new Level<Square>();
	}

	@Test
	public void testDungeonLongLongLong() {
		Dungeon<Square> lll = new Level<Square>(15,15);
		assertEquals(new Dimension(15,15,0),lll.getMaxDimension());
	}

	@Test(expected = IllegalArgumentException.class)
	public void testDungeonLongLongLongNegative() {
		Dungeon<Square> wrong = new Level<Square>(-5,-5);
		fail("one of the given coordinate values is not valid.");
	}
	
	@Test
	public void testDungeonDimension() {
		Dungeon<Square> dim = new Level<Square>(new Dimension(15,15,0));
		assertEquals(new Dimension(15,15,0),dim.getMaxDimension());
	}

	@Test
	public void testDungeon() {
		assertEquals(new Dimension(0,0,10),c.getMaxDimension());
	}

//	@Test
//	public void testRemoveRoom() {
//		v.addSquare(st, d);
//		Room<Square> room = new Room<Square>(v, st, d);
//		assertTrue(room.equals(v.getRoomOf(d)));
//		v.addSquare(st2, d2);
//		Room<Square> room2 = new Room<Square>(v, st2, d2);
//		assertTrue(v.getRooms().size()==2);
//		v.removeRoom(v.getRoomOf(d2));
//		assertTrue(v.getRooms().size()==1);
//	}
	
	@Test
	public void testSetMaxDimension() {
		v.setMaxDimension(new Dimension(80,80,0));
		assertEquals(new Dimension(80,80,0),v.getMaxDimension());
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testSetMaxDimensionLower() {
		v.setMaxDimension(new Dimension(10,10,0));
		fail();
	}

	@Test
	public void testAddSquare() {
		v.addSquare(st, d);
		v.addSquare(st2, d2);
		assertTrue(v.getDimensionOf(st2)!=null);
		assertTrue(v.getDimensionOf(st)!=null);
		assertTrue(v.getUsedDimensions().contains(d));
		assertTrue(v.getUsedDimensions().contains(d2));
		assertEquals(2,v.getRooms().size());
	}

	@Test
	public void testGetSquareAt() {
		v.addSquare(st, d);
		assertEquals(st,v.getSquareAt(d));
		assertEquals(st,v.getSquareAt(new Dimension(2,3,0)));
	}

	@Test
	public void testRemoveSquareAt() {
		v.addSquare(st,d);
		v.addSquare(st2, d2);
		v.removeSquareAt(d);
		assertTrue(st.isTerminated());
		assertTrue(v.getDimensionOf(st)==null);
	}

	@Test
	public void testIsInSameRoomAs() {
		v.addSquare(st, d);
		v.addSquare(st3, d3);
		assertTrue(v.isInSameRoomAs(st, st3));
	}

	@Test
	public void testGetUsedDimensions() {
		v.addSquare(st, d);
		HashSet<Dimension> dimensions = new HashSet<Dimension>();
		dimensions.add(d);
		HashSet<Dimension> dims = (HashSet<Dimension>) v.getUsedDimensions();
		assertEquals(dimensions, dims);
	}

	@Test
	public void testIsAvailable() {
		v.addSquare(st, d);
		assertFalse(v.isAvailable(d));
		assertTrue(v.isAvailable(d2));
	}

	@Test
	public void testGetRoomOfSquare() {
		v.addSquare(st, d);
		assertTrue(v.getRooms().contains(v.getRoomOf(st)));
		assertEquals(null,v.getRoomOf(st2));
	}

	@Test
	public void testGetRoomOfDimension() {
		v.addSquare(st, d);
		assertTrue(v.getRoomOf(d).getAllSquares().contains(st));
		assertEquals(null,v.getRoomOf(d2));
	}
	
}
